﻿Imports TNCDAL
Imports System.Data.Linq
Imports System.Linq

Public Class CReceiptVoucher
    Dim db As New TanNamChinhDataContext

    Public Function SelectRecordById(ByVal id As Integer) As tblReceiptVoucher
        Dim rv = (From p In db.tblReceiptVouchers
                 Where p.ID_ReceiptVoucher = id
                 Select p).Single
        Return rv
    End Function

    Public Sub Insert(ByVal obj As tblReceiptVoucher)
        db.tblReceiptVouchers.InsertOnSubmit(obj)
        db.SubmitChanges()
    End Sub

    Public Sub Update(ByVal obj As tblReceiptVoucher)
        Dim rv = SelectRecordById(obj.ID_ReceiptVoucher)
        rv.CreatedDate = obj.CreatedDate
        rv.Description = obj.Description
        rv.Payee = obj.Payee
        rv.PayDay = obj.PayDay
        db.SubmitChanges()
    End Sub

    Public Sub UpdateApprove(ByVal obj As tblReceiptVoucher)
        Dim rv = SelectRecordById(obj.ID_ReceiptVoucher)
        rv.IsApprove = obj.IsApprove
        rv.ID_ApproveUser = obj.ID_ApproveUser
        db.SubmitChanges()
    End Sub

    Public Sub Delete(ByVal id As Integer)
        Dim rv = SelectRecordById(id)
        db.tblReceiptVouchers.DeleteOnSubmit(rv)
        db.SubmitChanges()
    End Sub
End Class
